package cn.gson.springboot.controllers;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.springboot.model.pojos.Health;
import cn.gson.springboot.model.pojos.HealthProject;
import cn.gson.springboot.model.service.ApplyHosptialServices;
import cn.gson.springboot.model.vo.AppointmentVo;
import cn.gson.springboot.model.vo.HealthVo;

@Controller
public class PhysicalController {
	
	@Autowired
	private ApplyHosptialServices applyser;	//住院所有的service
	
	// 体检
	@RequestMapping("py-physical")
	public String pyphysical(Model model) {

		//生成随机数形成自主体检号
		int healthid=(int)((Math.random()*4+1)*100000);
		model.addAttribute("healthid", healthid);
		
		return "py-physical";
	}
	
	
	//体检登记
	@RequestMapping("py-checkupexamination")
	public String checkupexamination(Model model){
		
		//生成随机数形成医疗卡号
		int clinicid=(int)((Math.random()*4+1)*100000);
		model.addAttribute("clinicid", clinicid);
		
		return "py-checkupexamination";
	}
	
	//新增医疗卡,新增体检预约，新增体检表
	@PostMapping(value="add-healthoppoint2")
	@ResponseBody
	public String addhealthoppoint(AppointmentVo avo) {
		return  applyser.AddHealthOppoint2(avo);
	}
	
	//根据套餐查询具体的项目
	@PostMapping("find-mealprojectbyid")
	@ResponseBody
	public JSONArray selectMealProjectByid(Integer mno) {
		return applyser.selectMealProjectByid(mno);
	}
	
	//查询自主体检的记录
	@RequestMapping("init-appoint")
	@ResponseBody
	public JSONArray selectHealthAppointAll() {
		return applyser.selectHealthAppointAll();
	}
	
	//体检查看详情体检项目
	@PostMapping("init-appointdetails")
	@ResponseBody
	public JSONArray selectHealthAppointDetials(Integer clinicid) {
		return applyser.selectHealthAppointDetials(clinicid);
	}
	
	//查询体检报告
	@PostMapping("init-healthpro")
	@ResponseBody
	public Map<String,Object>  selectHealthproAll(@RequestParam("page")int page,
			@RequestParam("rows")int rows,String clinicname){
		//进行分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray healthrecord = applyser.selectHealthproAll(clinicname);
		System.out.println("体检报告姓名"+clinicname);
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", healthrecord);//封装当前页的内容
		return map;
	}

	
	//自主新增体检检查
	@PostMapping("add-ownhealths")
	@ResponseBody
	public String AddHealthOwn(String json) {
		JSONArray array = JSONArray.parseArray(json);
		String addheal =  applyser.AddHealthOwn(array);
		if("".equals(addheal)) {
			return "体检失败";
		}
		return "体检成功";
	}
	

	//查询门诊，住院的体检信息
	@RequestMapping("init-healthtwo")
	@ResponseBody
	public JSONArray selectHealTwoRecordAll() {
		return applyser.selectHealTwoRecordAll();
	}
	//门诊，住院体检的详情体检项目
	@RequestMapping("init-healthdetailstwo")
	@ResponseBody
	public JSONArray selectHealTwoRecordDetils(Integer clinicid) {
		return applyser.selectHealTwoRecordDetils(clinicid);
	}
	
	// 体检报告
	@RequestMapping("py-medicalreport")
	public void pymedicalreport() {

	}
	
	// 体检项目
	@RequestMapping("py-healproject")
	public void healProject() {

	}

	
	//新增体检项目[修改体检项目]
	@PostMapping("add-healthproject")
	@ResponseBody
	public void AddhealthProject(String projectName,String projectPrice,Integer sectionId) {
		applyser.AddhealthProject(projectName,projectPrice,sectionId);
	}
	//修改体检项目
	@PostMapping("update-healthproject")
	@ResponseBody
	public void UpdatehealthProject(String projectName,String projectPrice,Integer projectNo) {
		applyser.UpdatehealthProject(projectName,projectPrice,projectNo);
	}
	
	
}
